<template>
  <el-dialog title="问卷" :visible.sync="dialogFormVisible" :append-to-body="true" width="65%" @open="handleOpen" @close="handleClose" :close-on-click-modal="false" :close-on-press-escape="false">
    <question-naire1 @close="handleClose" @sum="handleSum" @step="val=>step=val" :buttonType="step===1?'next':'save'" v-show="questionObj.id === 1 || (questionObj.id ===2 && step === 1)"></question-naire1>
    <question-naire2 @close="handleClose" @sum="handleSum" v-show="questionObj.id === 3|| (questionObj.id ===2 && step === 2)"></question-naire2>
    <question-naire3 @close="handleClose" @sum="handleSum" v-show="questionObj.id === 4"></question-naire3>
  </el-dialog>
</template>
<script>
  import questionNaire1 from './questionNaire/questionNaire1'
  import questionNaire2 from './questionNaire/questionNaire2'
  import questionNaire3 from './questionNaire/questionNaire3'
  export default {
    data(){
      return{
        dialogFormVisible:false,
        goodControl:false,
        questionObj:{},
        step:'',
        result:'',
        sum:'',
      }
    },
    components:{
      questionNaire1,questionNaire2,questionNaire3
    },
    methods:{
      handleOpen(){

      },
      handleClose(){
        this.dialogFormVisible = false
        this.$emit('submit',{result:this.result,sum:this.sum,goodControl:this.goodControl})
      },
      handleSum(sum){
        this.sum = sum
        if(this.questionObj.id ===2 ||this.questionObj.id ===3){
          this.result += `${this.questionObj.name}：${sum>80?'控制良好':'控制不佳'}；`
          this.goodControl = sum>80
        }else {
          this.result += `${this.questionObj.name}：${sum > 19 ? '控制良好' : '控制不佳'}；`
          this.goodControl = sum>19
        }
      },
      showModal(questionObj){
        this.dialogFormVisible = true
        this.questionObj = questionObj;
        if(questionObj.id == 2){
          this.step = 1
        }
      }
    }
  }
</script>

